// pages/mine/mine.js

const app = getApp()

Page({
  data: {
    checked:false,
    userInfo: {},
    hasUserInfo: true,
    depot_status:true,
    pinless:'登录/注册仓库',
    warehouseId:0,
    company_name:'',
    whName:'',
  },
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    
    wx.getUserProfile({
      desc: '用于完善会员资料', 
      // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: false
        });
        let userInfo =res.userInfo;
        
        wx.setStorage({
          key:"userInfo",
          data:userInfo,
        });
      }
    })
  },

  pinless(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  setting(){
    wx.navigateTo({
      url: '/pages/setting/setting',
    })
  },
  
  onLoad: function (options) {
    let userInfo = wx.getStorageSync('userInfo')
    let warehouseId = wx.getStorageSync('warehouseId')
    let company_name = wx.getStorageSync('company_name')
    let whName = wx.getStorageSync('whName')

    // console.log(warehouseId)
    // console.log(company_name)
    if(userInfo){
      this.setData({
        userInfo,
        hasUserInfo: false,
      })
    }
    if(warehouseId){
      this.setData({
        warehouseId,
        depot_status:false,
        checked:true,
      })
    }
    if(company_name){
      this.setData({
        company_name,
      })
    }
    if(whName){
      this.setData({
        whName,
      })
    }
  },
  
})